package com.jvup.gameshow.controller;

import android.view.MenuItem;

import androidx.annotation.NonNull;

import com.jvup.common.support.base.EventController;
import com.jvup.gameshow.R;
import com.jvup.gameshow.activity.HomeActivity;
import com.jvup.common.constant.Navigation;
import com.jvup.gameshow.model.viewModel.impl.MallViewModel;
import com.qire.antsbinder.viewModel.ViewModelFactory;
import com.qire.antsrouter.AntsRouter;
import com.qire.antsrouter.card.FloorCard;
import com.qire.antsrouter.card.RoomCard;

public class HomeEventController extends EventController<HomeActivity> {

    public HomeEventController(HomeActivity activity) {
        super(activity);
    }

    @Override
    protected void bindView() {
        //        owner.viewDataBinder().setVariable(BR.homeEventController,this);
        if(owner.viewDataBinder().getHomeEventController() == null) {
            owner.viewDataBinder().setHomeEventController(this);
        }
    }

    /**
     * 底部导航按钮切换
     * @param menuItem
     * @return
     */
    public boolean onNavigationItemSelected(@NonNull MenuItem menuItem){
        switch (menuItem.getItemId()){
            case R.id.app_home_menu_home:
                AntsRouter.ROUTER.<RoomCard>buildCard(Navigation.Fragment.HomeFragment).to(owner,R.id.frame_home);
                return true;
            case R.id.app_home_menu_mall:
                AntsRouter.ROUTER.<RoomCard>buildCard(Navigation.Fragment.MallFragment)
                        .withData("viewModel", ViewModelFactory.crate(owner, MallViewModel.class))
                        .to(owner,R.id.frame_home);
                return true;
            case R.id.app_home_menu_player_show:
                AntsRouter.ROUTER.<RoomCard>buildCard(Navigation.Fragment.PlayerShowFragment).to(owner,R.id.frame_home);
                return true;
            case R.id.app_home_menu_order:
                AntsRouter.ROUTER.<RoomCard>buildCard(Navigation.Fragment.OrderFragment).to(owner,R.id.frame_home);
                return true;
            case R.id.app_home_menu_user:
                AntsRouter.ROUTER.<RoomCard>buildCard(Navigation.Fragment.UserCenterFragment).to(owner,R.id.frame_home);
                return true;
        }
        return false;
    }

    public void onNavigationItemReselected(@NonNull MenuItem menuItem){
        if(menuItem.getItemId() == R.id.app_home_menu_home) {
            AntsRouter.ROUTER.<RoomCard>buildCard(Navigation.Fragment.HomeFragment).to(owner,R.id.frame_home);
            return ;
        }
        if(menuItem.getItemId() == R.id.app_home_menu_player_show) {
            AntsRouter.ROUTER.<FloorCard>buildCard(Navigation.Page.ShareIdeaPage).navigation();
            return ;
        }
    }

}
